<?php

namespace api\controller;

// +----------------------------------------------------------------------
// | 工序上游数据控制层
// +----------------------------------------------------------------------

use common\controller\VerifyController;
use common\service\StepService;
use common\validate\StepUpstream;
use support\ErrorCode;
use think\Request;

class StepUpstreamController extends VerifyController
{
    /**
     * @var \common\service\StepService
     */
    protected $stepService;

    public function __construct()
    {
        parent::__construct();
        $this->stepService = StepService::getInstance();
    }

    /**
     * 获取指定工序的Upstream配置
     * @param Request $request
     * @return \think\Response
     * @throws \Exception
     */
    public function getStepUpstream(Request $request)
    {
        $param = $request->param();
        $stepId = $param['param']['filter']['step_id'] ?? 0;
        $projectId = $param['param']['filter']['project_id'] ?? 0;
        $projectTemplateId = $param['param']['filter']['project_template_id'] ?? 0;
        $stepWorkflowId = $param['param']['filter']['step_workflow_id'] ?? 0;
        $resData = $this->stepService->getStepUpstream($stepId, $projectTemplateId, $projectId, $stepWorkflowId);
        return json(success_response('', $resData));
    }

    /**
     * 获取所有工序的Upstream配置
     * @param Request $request
     * @return \think\Response
     * @throws \Exception
     */
    public function getAllUpstream(Request $request)
    {
        $param = $request->param();
        $projectTemplateId = $param['param']['project_template_id'] ?? 0;
        $projectId = $param['param']['project_id'] ?? 0;
        $resData = $this->stepService->getAllUpstream($projectTemplateId, $projectId);
        return json(success_response('', $resData));
    }
}
